using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace CubicFWNet.Data.Models.Mapping
{
    public class NewsMap : EntityTypeConfiguration<News>
    {
        public NewsMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Id, t.IsLimit, t.UserList, t.Sort, t.Status, t.CreatorID });

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(128);

            this.Property(t => t.Publisher)
                .HasMaxLength(64);

            this.Property(t => t.IsLimit)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.UserList)
                .IsRequired();

            this.Property(t => t.Sort)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("News");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.Introduct).HasColumnName("Introduct");
            this.Property(t => t.NewsContent).HasColumnName("NewsContent");
            this.Property(t => t.Publisher).HasColumnName("Publisher");
            this.Property(t => t.IsLimit).HasColumnName("IsLimit");
            this.Property(t => t.UserList).HasColumnName("UserList");
            this.Property(t => t.Sort).HasColumnName("Sort");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.CreatorID).HasColumnName("CreatorID");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
        }
    }
}
